/*
 * 描          述:  <描述>
 * 修  改   人:  Administrator
 * 修改时间:  2018年6月3日
 * <修改描述:>
 */
package com.tx.component.servicelogger.support.mybatis;

import com.tx.component.servicelogger.support.ServiceLogger;
import com.tx.component.servicelogger.support.ServiceLoggerMapper;
import org.slf4j.Logger;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * 实体持久层注册器<br/>
 * <功能详细描述>
 * 
 * @author  Administrator
 * @version  [版本号, 2018年6月3日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class ServiceLoggerFactory<T>
        implements FactoryBean<ServiceLogger>, InitializingBean {
    
    private Logger logger = org.slf4j.LoggerFactory
            .getLogger(ServiceLoggerFactory.class);
    
    /** 日志类型 */
    private Class<T> beanType;

    private ServiceLoggerMapper baseMapper;

    private ServiceLogger serviceLogger;
    
    /** <默认构造函数> */
    public ServiceLoggerFactory(Class<T> beanType, ServiceLoggerMapper baseMapper) {
        super();
        this.beanType = beanType;
        this.baseMapper = baseMapper;
    }
    
    /**
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() {
        logger.info("   --- 通过ServiceLoggerFactory构建业务日志句柄.BeanType:{}", this.beanType.getName());
        this.serviceLogger = new DefaultServiceLoggerImpl<>(this.beanType,this.baseMapper);

    }
    
    /**
     * @return
     */
    @Override
    public boolean isSingleton() {
        return true;
    }
    
    /**
     * @return
     */
    @Override
    public Class<?> getObjectType() {
        return ServiceLogger.class;
    }
    
    /**
     * @return
     * @throws Exception
     */
    @Override
    public ServiceLogger getObject(){
        return this.serviceLogger;
    }
}
